package chapter02

import chapter01.Student

object Test07_DataType {
  def main(args: Array[String]): Unit = {
    //1 整数类型
    val a1: Byte = 127 //128就会超出范围
    val a2 = 12 //默认Int
    val a3: Long = 465464265778646L //长整数类型
    val b1: Byte = 10
    val b2: Byte = (10 + 20)
    println(b2)
    val b3: Byte = (b1 + 20).toByte
    println(b3)
    //2. 浮点类型
    val f1: Float = 1.23456f
    val d1 = 36.36
    //3. 字符类型
    val c1: Char = 'a'
    println(c1)
    val c2: Char = '9'
    println(c2)
    val c3: Char = '\t'
    println("abc" + c3 + "def")
    //4.字符变量底层保存ASCII码
    val i1: Int = c1
    val i2: Int = c2
    println("i1=" + i1)
    println("i2=" + i2)
    val c7: Char = (i1 + 1).toChar
    val c8: Char = (i2 + 1).toChar
    println("c7=" + c7)
    println("c8=" + c8)

    //5 空类型
    //5.1空值Unit
    def m1(): Unit = println("m1被调用")

    val a = m1()
    println("a: " + a + "a.class" + a.getClass.getName)
    //5.2空引用null
    var student: Student = new Student("alice", 20)
    student = null
    println(student)

    //5.3 Nothing
    def m2(n: Int): Int = {
      if (n == 0)
        throw new NullPointerException
      else
        n
    }

    val b = m2(0)
    println(b)

  }
}
